package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
/**
 * User interface to the DVD controller
 * @author(Gruppe B)
 * @version 1.0 (9-11-2013)           
 */

public class DvdUI
{
    private DVDCtr dvdCtr;
    private String trueTitle;
    
    /**
     * Does nothing.
     */
    public DvdUI()
    {
        
    }
    
    /**
     * This method calls the DVD controller class, and then calls the dvd Menu method.
     */
    public void start()
    {
        dvdCtr =  new DVDCtr();
        dvdMenu();
    }
    
    /**
     * This is the dvd menu method. Depends on the user input it does several things. 
     * On input 1 it shows information about a wanted element.
     * On input 2 it creates a new DVD and takes several inputs to define the fields.
     * On input 3 it alters the number of copies of the respective DVD.
     * On input 4 it deletes the found DVD, it finds the DVD through a search string.
     * On input 5 it Prints a list of all the DVDs found in the array list.
     * If input is something else than 1,2,3,4,5 it exits the while loop and returns to the main menu.
     * Uses the choice variable from the write DVD menu method as input.
     */
    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choice =   writeDVDMenu();
            if (choice == 1)
            {
                trueTitle = findDVD();
                dvdCtr.getDVD(trueTitle);
                System.out.println("Is this the DVD you were looking for?");
                System.out.println("If yes type ok else type no");
                Scanner keyboard = new Scanner(System.in);
                String input = keyboard.nextLine(); 
            }
            else
            {
                    if(choice == 2)
                    {
                        String title = inputTitle();
                        String genre = inputGenre();
                        String releaseDate = inputReleaseDate();
                        String language = inputLanguage();
                        String subtitle = inputSubtitle();
                        double playTime = inputPlayTime();
                        int copy = inputCopy();                        
                        dvdCtr.createDVD(title, genre, releaseDate, language, subtitle, playTime, copy);
                }
                else
                {
                    if(choice == 3)
                    {
                        trueTitle = findDVD();
                        int copy = inputCopy();
                        dvdCtr.setNoOfCopies(trueTitle, copy);
                        dvdCtr.getDVD(trueTitle);
                        Scanner keyboard = new Scanner(System.in);
                        String input = keyboard.nextLine();
                    }
                    else
                    {
                        if(choice == 4)
                        {
                            trueTitle = findDVD();
                            dvdCtr.getDVD(trueTitle);
                            dvdCtr.deleteDVD(trueTitle);
                            Scanner keyboard = new Scanner(System.in);
                            String input = keyboard.nextLine();
                        }
                        else
                        {
                            if(choice == 5)
                            {
                                dvdCtr.listAllDVDs();
                                Scanner keyboard = new Scanner(System.in);
                                String input = keyboard.nextLine();
                            }
                            else
                            {
                                exit = true;
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else            
        }//end while
    }
    
    /**
     * This method prints several lines of text, it takes input and returns the choice variable.
     */
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD description");
            System.out.println(" (3) Set number of copies");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Return");
            System.out.print("\n Make your choice: ");            
            int choice = keyboard.nextInt();
            return choice;
    }
            
    /**
     * This method gets input from the scanner and then assigns title to the new input and returns it for use in the DVD menu method
     */
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
    
    /**
     * This method gets input from the scanner and then assigns genre to the new input and returns it for use in the DVD menu method
     */
    private String inputGenre()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD genre: " );
        String genre = keyboard.nextLine();
        return genre;
    }
    
    /**
     * This method gets input from the scanner and then assigns releaseDate to the new input and returns it for later in the DVD menu method
     */
    private String inputReleaseDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD release date: " );
        String releaseDate = keyboard.nextLine();
        return releaseDate;
    }
    
    /**
     * This method gets input from the scanner and then assigns language to the new input and returns it for use in the DVD menu method
     */
    private String inputLanguage()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD language: " );
        String language = keyboard.nextLine();
        return language;
    }
    
    /**
     * This method gets input from the scanner and then assigns subtitle to the new input and returns it for use in the DVD menu method
     */
    private String inputSubtitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD subtitle: " );
        String subtitle = keyboard.nextLine();
        return subtitle;
    }
    
    /**
     * This method gets input from the scanner and then assigns playTime to the new input and returns it for use in the DVD menu method
     */
    private double inputPlayTime()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD play time: " );
        double playTime = keyboard.nextDouble();
        return playTime;
    }
    
    /**
     * This method gets input from the scanner and then assigns copy to the new input and returns it for use in the DVD menu method
     */
    private int inputCopy()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the number os copies: ");
        int copy = keyboard.nextInt();
        return copy;
    }
    
    /**
     * This method assigns a string input to a variable, stored for use for the DVD menu method.
     */
    private String findDVD()
    {  
        boolean ok = false;
        String title = null;
        while(!ok)
        {
           // makes an object keyboard to have input from the console
           Scanner keyboard = new Scanner(System.in);
           System.out.println(" Write title:  ");
           try{
             title = keyboard.nextLine();
             ok = true;             
           }
           catch (Exception e)
            {
             System.out.println("You must enter a title -  try again");
             String input = keyboard.nextLine();
           }
        }//end while
        return title;
    }
}